package com.small.common.other;

import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * Instant——它代表的是时间戳 LocalDate——不包含具体时间的日期，比如2014-01-14。它可以用来存储生日，周年纪念日，入职日期等。
 * LocalTime——它代表的是不含日期的时间 LocalDateTime——它包含了日期及时间，不过还是没有偏移信息或者说时区。
 * ZonedDateTime——这是一个包含时区的完整的日期时间，偏移量是以UTC/格林威治时间为基准的。
 */
public class LocalDateTest {

    public static void main(String[] args) {
        LocalDate today = LocalDate.now();
        System.out.println("Today's Local date : " + today);

        int year = today.getYear();
        int month = today.getMonthValue();
        int day = today.getDayOfMonth();
        System.out.printf("Year : %d Month : %d day : %d \t %n", year, month, day);

        LocalDate dateOfBirth = LocalDate.of(2010, 01, 14);
        System.out.println("Your Date of birth is : " + dateOfBirth);

        LocalDate date1 = LocalDate.of(2018, 12, 27);
        if (date1.equals(today)) {
            System.out.printf("Today %s and date1 %s are same date %n", today, date1);
        }
        LocalTime now = LocalTime.now();
        LocalTime frontTime = now.plusHours(-1);
        LocalTime timeStart = LocalTime.of(frontTime.getHour(), 0, 0);
        LocalTime timeEnd = LocalTime.of(now.getHour(), 0, 0);
        System.out.println("timeStart "+timeStart);
        System.out.println("timeEnd "+timeEnd);
//        LocalDate nextWeek = today.plus(1, ChronoUnit.WEEKS);
//        System.out.println("Today is : " + today);
//        System.out.println("Date after 1 week : " + nextWeek);
//
////        LocalDate tomorrow = LocalDate.of(2018, 12, 28);
//        LocalDate tomorrow = today.plusDays(1);
//        if (tomorrow.isAfter(today)) {
//            System.out.println("Tomorrow "+tomorrow);
//        }
//        LocalDate yesterday = today.minusDays(1);
//        if (yesterday.isBefore(today)) {
//            System.out.println("Yesterday  "+yesterday);
//        }
//        
//        Instant timestamp = Instant.now(); 
//        System.out.println("What is value of this instant " + timestamp); 
//
//        String dayAfterTommorrow = "20140116"; 
//        LocalDate formatted = LocalDate.parse(dayAfterTommorrow, 
//        DateTimeFormatter.BASIC_ISO_DATE); 
//        System.out.printf("Date generated from String %s is %s %n", dayAfterTommorrow, formatted); 
//
//        
//        LocalDateTime arrivalDate = LocalDateTime.now(); 
//        try { 
//            DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a"); 
//            String landing = arrivalDate.format(format); 
//            System.out.printf("Arriving at : %s %n", landing); 
//            } catch (DateTimeException ex) { 
//            System.out.printf("%s can't be formatted!%n", arrivalDate); 
//            ex.printStackTrace(); 
//        } 

    }
}
